package com.mcf.xiaolinju.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mcf.xiaolinju.vo.phoneReturn;
import com.mcf.xiaolinju.entity.Phone;
import com.mcf.xiaolinju.service.impl.PhoneServiceImpl;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author mcf
 * @since 2021-11-23
 */
@CrossOrigin
@RestController
@RequestMapping("/xiaolinju/phone")
public class PhoneController {
    @Resource
    PhoneServiceImpl phoneService;
    //模糊查询
    @RequestMapping("/pageSelectPhonedim")
    public Page<phoneReturn> pageSelectPhonedim(int pageNo,int pageSize,int id,String name,String work,String phonenum){
        return phoneService.selectPhonedim(new Page<phoneReturn>(pageNo,pageSize),id,name,work,phonenum);
    }
    //分页查询
    @RequestMapping("/pageSelectPhone")
    public Page<phoneReturn> pageSelectPhone(int pageNo, int pageSize, int id){
        return  phoneService.selectPhone(new Page<phoneReturn>(pageNo,pageSize),id);
    }
    //添加
    @RequestMapping("/add")
    public String add(Phone phone){
        Date date=new Date();
        LocalDateTime ldt=date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
        phone.setCreatetime(ldt);
        if(phoneService.save(phone)){
            return "添加成功";
        }
        return "添加失败";
    }
    //修改
    @RequestMapping("/update")
    public String update(int id,String phone,String name,String work,int updateid){
        return phoneService.updatePhone(id,phone,name,work,updateid);
    }
    //删除
    @RequestMapping("/del")
    public String del(int id,int updateid) {
    return  phoneService.del(id,updateid);
    }
    //主键查询
    @RequestMapping("/getById")
    public Phone getById(int id){

        return  phoneService.getById(id);
    }
    //批量删除
    @RequestMapping("/delmany")
    public String delmany( Integer[] id,int updateid){
       return phoneService.delmany(id,updateid);
    }
    //小程序查询信息
    @RequestMapping("/selectapi")
    public List<Phone> selectapi(int villageid,String workname){


        return   phoneService.selectapi(villageid,workname);
    }

}
